/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DigiRobo;

import java.awt.Graphics2D;
import java.awt.geom.Point2D;

/**
 *
 * @author v034150
 */
public class NingyoStep {

    public final static double STEP_SIZE = 28.0;
    public final static int MIN_ROTATION_STEPS = 3;
    public final static int MAX_ROTATION_STEPS = 21;
    private Direction _Direction = null;
    public NingyoStepVisual Visual = null;
    
    public class NingyoStepException extends Exception {
        private String _message;
        NingyoStepException(String message) {
            _message = message;
        }
        @Override
        public String toString() {
            return "NingyoStepException[ " + _message + " ]";
        }
    }

    public void draw(Graphics2D g) {
        if (Visual != null) {
            Visual.draw(g);
        }
    }
    
    public boolean isInside(double x, double y) {
        if (Visual != null) {
            return Visual.isInside(x,y);
        } else {
            return false;
        }
    }

    public boolean isInside(Point2D.Double p) {
        if (Visual != null) {
            return Visual.isInside(p);
        } else {
            return false;
        }
    }
    
    public Direction getDirection() {
        return _Direction;
    }

    public void setDirection(Direction Direction) {
        this._Direction = Direction;
    }

    @Override
    public String toString() {
        return getDirection().toString();
    }
    
    public enum Direction {
        S, L, R, Stop;      
        @Override
        public String toString() {
            String Representation = new String();
            switch(this) {
                case S:
                    Representation = "S";
                    break;                
                case R:
                    Representation = "R";
                    break;                
                case L:
                    Representation = "L";
                    break;                
                case Stop:
                    Representation = "Stop";
                    break;                
                default:
                    Representation = "Unknown (=" + this + ")";
                    break;
            }
            return Representation;
        }

        public boolean isRotation() {
            if ( (this == L) || (this==R) ) {
                return true;
            } else {
                return false;
            }
        }
    }
}
